home *** CD-ROM | disk | FTP | other *** search
Text File | 1991-02-26 | 11.2 KB | 424 lines | [TEXT/MPS ] |
- /*
- Modified from HyperXcmd.glue.inc by
- Jeff E Mandel MD MS
- Department of Anesthesiology
- Tulane University School of Medicine
- 1430 Tulane Ave.
- New Orleans, LA 70112
-
- THyperXCmd.h
- portions ©Apple Computer, Inc. 1987
- All Rights Reserved.
-
- */
-
- #include <THyperXCmd.h>
-
- #include <memory.h>
- #include <String.h>
- #include <Strings.h>
- #include <Errors.h>
-
- pascal long TXCMDBlock::StringLength(StringPtr strPtr)
- /* Count the characters from where strPtr points until the next zero byte.
- Does not count the zero itself. strPtr must be a zero-terminated string. */
- {
- inArgs[0] = (long)strPtr;
- request = xreqStringLength;
- ((MyProcPtr) entryPoint)();
- return (long) outArgs[0];
- }
-
- pascal void TXCMDBlock::SendCardMessage(StringPtr msg)
- /* Send a HyperCard message (a command with arguments) to the current card.
- msg is a pointer to a Pascal format string. */
- {
- inArgs[0] = (long)msg;
- request = xreqSendCardMessage;
- ((MyProcPtr) entryPoint)();
- }
-
- pascal Handle TXCMDBlock::EvalExpr(StringPtr expr)
- /* Evaluate a HyperCard expression and return the answer. The answer is
- a handle to a zero-terminated string. */
- {
- inArgs[0] = (long)expr;
- request = xreqEvalExpr;
- ((MyProcPtr) entryPoint)();
- return (Handle)(outArgs[0]);
- }
-
- pascal void TXCMDBlock::ZeroToPas(char *zeroStr, StringPtr pasStr)
- {
- inArgs[0] = (long)zeroStr;
- inArgs[1] = (long)pasStr;
- request = xreqZeroToPas;
- ((MyProcPtr) entryPoint)();
- }
-
- pascal Handle TXCMDBlock::PasToZero(StringPtr pasStr)
- {
- inArgs[0] = (long)pasStr;
- request = xreqPasToZero;
- ((MyProcPtr) entryPoint)();
- return (Handle) outArgs[0];
- }
-
- pascal void TXCMDBlock::SendHCMessage(StringPtr msg)
- /* Send a HyperCard message (a command with arguments) to HyperCard.
- msg is a pointer to a Pascal format string. */
- {
- inArgs[0] = (long)msg;
- request = xreqSendHCMessage;
- ((MyProcPtr) entryPoint)();
- }
-
- pascal Handle TXCMDBlock::GetGlobal(StringPtr globName)
- /* Return a handle to a zero-terminated string containing the value of
- the specified HyperTalk global variable. */
- {
- inArgs[0] = (long)globName;
- request = xreqGetGlobal;
- ((MyProcPtr) entryPoint)();
- return (Handle)(outArgs[0]);
- }
-
- pascal void TXCMDBlock::SetGlobal(StringPtr globName, Handle globValue)
- /* Set the value of the specified HyperTalk global variable to be
- the zero-terminated string in globValue. The contents of the
- Handle are copied, so you must still dispose it afterwards. */
- {
- inArgs[0] = (long)globName;
- inArgs[1] = (long)globValue;
- request = xreqSetGlobal;
- ((MyProcPtr) entryPoint)();
- }
-
- pascal Handle TXCMDBlock::GetFieldByName(Boolean cardFieldFlag, StringPtr fieldName)
- /* Return a handle to a zero-terminated string containing the value of
- field fieldName on the current card. You must dispose the handle. */
- {
- inArgs[0] = (long)cardFieldFlag;
- inArgs[1] = (long)fieldName;
- request = xreqGetFieldByName;
- ((MyProcPtr) entryPoint)();
- return (Handle)(outArgs[0]);
- }
-
- pascal Handle TXCMDBlock::GetFieldByNameC(Boolean cardFieldFlag, CString fieldName)
- /* Return a handle to a zero-terminated string containing the value of
- field fieldName on the current card. You must dispose the handle. */
- {
- StringPtr p=(StringPtr) fieldName;
- inArgs[0] = (long)cardFieldFlag;
- inArgs[1] = (long)p;
- request = xreqGetFieldByName;
- ((MyProcPtr) entryPoint)();
- return (Handle)(outArgs[0]);
- }
-
- pascal void TXCMDBlock::SetFieldByNameC(Boolean cardFieldFlag, CString fieldName,
- Handle fieldVal)
- /* Set the value of field fieldName to be the zero-terminated string
- in fieldVal. The contents of the Handle are copied, so you must
- still dispose it afterwards. */
- {
- StringPtr p=(StringPtr) fieldName;
- inArgs[0] = (long)cardFieldFlag;
- inArgs[1] = (long)p;
- inArgs[2] = (long)fieldVal;
- request = xreqSetFieldByName;
- ((MyProcPtr) entryPoint)();
- DisposHandle(fieldVal);
- }
-
- pascal Handle TXCMDBlock::GetFieldByNum(Boolean cardFieldFlag, short fieldNum)
- /* Return a handle to a zero-terminated string containing the value of
- field fieldNum on the current card. You must dispose the handle. */
- {
- inArgs[0] = (long)cardFieldFlag;
- inArgs[1] = fieldNum;
- request = xreqGetFieldByNum;
- ((MyProcPtr) entryPoint)();
- return (Handle)(outArgs[0]);
- }
-
- pascal Handle TXCMDBlock::GetFieldByID(Boolean cardFieldFlag, short fieldID)
- /* Return a handle to a zero-terminated string containing the value of
- the field whise ID is fieldID. You must dispose the handle. */
- {
- inArgs[0] = (long)cardFieldFlag;
- inArgs[1] = fieldID;
- request = xreqGetFieldByID;
- ((MyProcPtr) entryPoint)();
- return (Handle)(outArgs[0]);
- }
-
- pascal void TXCMDBlock::SetFieldByName(Boolean cardFieldFlag, StringPtr fieldName,
- Handle fieldVal)
- /* Set the value of field fieldName to be the zero-terminated string
- in fieldVal. The contents of the Handle are copied, so you must
- still dispose it afterwards. */
- {
- inArgs[0] = (long)cardFieldFlag;
- inArgs[1] = (long)fieldName;
- inArgs[2] = (long)fieldVal;
- request = xreqSetFieldByName;
- ((MyProcPtr) entryPoint)();
- DisposHandle(fieldVal);
- }
-
- pascal void TXCMDBlock::SetFieldByNum(Boolean cardFieldFlag, short fieldNum,
- Handle fieldVal)
- /* Set the value of field fieldNum to be the zero-terminated string
- in fieldVal. The contents of the Handle are copied, so you must
- still dispose it afterwards. */
- {
- inArgs[0] = (long)cardFieldFlag;
- inArgs[1] = fieldNum;
- inArgs[2] = (long)fieldVal;
- request = xreqSetFieldByNum;
- ((MyProcPtr) entryPoint)();
- DisposHandle(fieldVal);
- }
-
- pascal void TXCMDBlock::SetFieldByID(Boolean cardFieldFlag, short fieldID,
- Handle fieldVal)
- /* Set the value of the field whose ID is fieldID to be the zero-
- terminated string in fieldVal. The contents of the Handle are
- copied, so you must still dispose it afterwards. */
- {
- inArgs[0] = (long)cardFieldFlag;
- inArgs[1] = fieldID;
- inArgs[2] = (long)fieldVal;
- request = xreqSetFieldByID;
- ((MyProcPtr) entryPoint)();
- DisposHandle(fieldVal);
- }
-
- pascal Boolean TXCMDBlock::StrToBool(char *str)
- /* Convert the Pascal strings 'true' and 'false' to booleans. */
- {
- inArgs[0] = (long) str;
- request = xreqStrToBool;
- ((MyProcPtr) entryPoint)();
- return (Boolean) outArgs[0];
- }
-
- pascal long TXCMDBlock::StrToLong(char *str)
- /* Convert a string of ASCII decimal digits to an unsigned long integer. */
- {
- inArgs[0] = (long)str;
- request = xreqStrToLong;
- ((MyProcPtr) entryPoint)();
- return (long) outArgs[0];
- }
-
- pascal void TXCMDBlock::LongToStr(long num,StringPtr mystr)
- {
- inArgs[0] = num;
- inArgs[1] = (long)mystr;
- request = xreqLongToStr;
- ((MyProcPtr) (entryPoint))();
- }
-
- pascal void TXCMDBlock::SendCardMessageC(CString msg)
- /* Send a HyperCard message (a command with arguments) to the current card.
- msg is a CString. */
- {
- char *p=(char *)msg;
- c2pstr(p);
- inArgs[0] = (long)p;
- request = xreqSendCardMessage;
- ((MyProcPtr) entryPoint)();
- }
-
- void TXCMDBlock::SignalFatalError(char *msg)
- {
-
- CString theMessage((char *)"answer \"");
- theMessage += CString (msg) + CString("\"");
- SendCardMessageC(theMessage);
- SignalReturnStatus("\p#@!%");
- }
-
- void TXCMDBlock::SignalFatalError(CString msg)
- {
-
- CString theMessage((char *)"answer \"");
- theMessage += msg + CString("\"");
- SendCardMessageC(theMessage);
- SignalReturnStatus("\p#@!%");
- }
-
- void TXCMDBlock::SignalReturnStatus (StringPtr theMessage)
- {
- returnValue = PasToZero(theMessage);
- return;
- }
-
- void TXCMDBlock::SignalReturnStatus (Handle theMessage)
- {
- returnValue = theMessage;
- return;
- }
-
- void TXCMDBlock::SignalReturnStatus (Ptr theMessage)
- {
- StringPtr p = (StringPtr) new char[256];
- strcpy((Ptr) p, theMessage);
- c2pstr((Ptr) p);
- returnValue = PasToZero(p);
- delete p;
- return;
- }
-
- void TXCMDBlock::SignalReturnStatus (CString theMessage)
- {
- returnValue = (Handle) theMessage;
- return;
- }
-
- Boolean TXCMDBlock::informArgNums(char *theXCMD, short expected)
- {
-
-
- if (paramCount==expected)
- return(true);
- else
- {
- CString theMessage((char *)"answer \"");
- theMessage += CString(theXCMD) + CString((char *)" requires ")
- + CString ((long) expected);
- if (expected==1)
- theMessage += CString((char *)" argument.\" ");
- else
- theMessage += CString((char *)" arguments.\" ");
-
- SendCardMessageC (theMessage);
- SignalReturnStatus("\p#@!%");
- return(false);
- }
- }
-
- Boolean TXCMDBlock::RecoverBooleanArg(short theNum)
- {
- HLock(params[theNum]);
- Ptr temp = new char[64];
- strcpy(temp, *params[theNum]);
- c2pstr(temp);
- Boolean theResult = StrToBool(temp);
- HUnlock(params[theNum]);
- delete temp;
- return theResult;
- }
-
- Ptr TXCMDBlock::RecoverStringArg(short theNum)
- {
- HLock(params[theNum]);
- Ptr result = new char[(Size) strlen(*params[theNum])];
- strcpy(result, *params[theNum]);
- HUnlock(params[theNum]);
- return result;
- }
-
- void TXCMDBlock::CopyStringArg(short theNum, StringPtr theString)
- {
- HLock(params[theNum]);
- strcpy((char *) theString, *params[theNum]);
- c2pstr((char *) theString);
- HUnlock(params[theNum]);
- }
-
- void TXCMDBlock::CopyStringArg(short theNum, Ptr theString)
- {
- HLock(params[theNum]);
- strcpy(theString, *params[theNum]);
- HUnlock(params[theNum]);
- }
-
- CString TXCMDBlock::CStringArg(short theNum)
- {
- HLock(params[theNum]);
- CString theResult = CString( *params[theNum]);
- HUnlock(params[theNum]);
- return theResult;
- }
-
- long TXCMDBlock::RecoverLongArg(short theNum)
- {
- HLock(params[theNum]);
- Ptr temp = new char[64];
- strcpy(temp, *params[theNum]);
- c2pstr(temp);
- long theResult = StrToLong(temp);
- HUnlock(params[theNum]);
- delete temp;
- return theResult;
- }
-
- long TXCMDBlock::RecoverLongGlobal(StringPtr globName)
- {
- Handle theString=GetGlobal(globName);
- if (strlen(*theString))
- {
- HLock(theString);
- StringPtr zeroStr= (StringPtr) new char[256];
- ZeroToPas(*theString, zeroStr);
- long result=StrToLong((char *) zeroStr);
- DisposHandle(theString);
- delete zeroStr;
- return (result);
- }
- else
- return 0;
-
- }
-
- void TXCMDBlock::SetLongGlobal(StringPtr globName, long theVal)
- {
- StringPtr tempStringPtr= (StringPtr) new char[256];
- LongToStr(theVal, tempStringPtr);
- Handle theString= PasToZero(tempStringPtr);
- SetGlobal(globName, theString);
- delete tempStringPtr;
- DisposHandle(theString);
- return;
- }
-
- void TXCMDBlock::SignalFileErr(OSErr theErr)
- {
- CString temp;
- switch (theErr)
- {
- case fnfErr: returnValue = (Handle)NewString("\pFile not found!");
- break;
- case bdNamErr: returnValue = (Handle)NewString("\pFile name bad!");
- break;
- case dupFNErr: returnValue = (Handle)NewString("\pFile already exists!");
- break;
- case ioErr: returnValue = (Handle)NewString("\pFile IO error!");
- break;
- case nsvErr: returnValue = (Handle)NewString("\pFile volume does not exist!");
- break;
- case extFSErr: returnValue = (Handle)NewString("\pFile system error!");
- break;
- case rfNumErr: returnValue = (Handle)NewString("\pFile refNum bad!");
- break;
- case fnOpnErr: returnValue = (Handle)NewString("\pFile not open!");
- break;
- case paramErr: returnValue = (Handle)NewString("\pFile parameter error!");
- break;
- case eofErr: returnValue = (Handle)NewString("\pFile end encountered!");
- break;
- case resNotFound: returnValue = (Handle)NewString("\pFile does not contain resource!");
- break;
- default: temp = CString("Unknown file err (") + CString((long)theErr) + CString(")");
- returnValue = (Handle)NewString((StringPtr)temp);
- break;
- }
- HLock(returnValue);
- p2cstr((StringPtr) *returnValue);
- HUnlock(returnValue);
- return;
- }